﻿using System;

class ElementBiggerThanNeighbours

            // Write a method that checks if the element at given position in given array of integers is bigger than its two neighbors (when such exist).

{
    static void Main(string[] args)
    {
        Console.Write("Enter the length of the array: ");
        int arraySize = int.Parse(Console.ReadLine());
        int[] array = new int[arraySize];
        Console.WriteLine();

        Console.WriteLine("Enter the elements of the array:");
        for (int i = 0; i < arraySize; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine();

        Console.Write("Enter the position you wish to check: ");
        int position = int.Parse(Console.ReadLine());

        CompareToNeighbours(array, position);
    }

    private static void CompareToNeighbours(int[] array, int position)
    {
        bool isGreater = false;
        if (position > array.Length - 1 || position < 0)
        {
            Console.WriteLine("There is no such position in that array!"); 
            return;
        }
        if (position == 0)
        {
            if (array[position] > array[position + 1])
            {
                isGreater = true;
            }
        }
        else if (position == array.Length - 1)
        {
            if (array[position] > array[position - 1])
            {
                isGreater = true;
            }
        }
        else if (array[position] > array[position - 1] && array[position] > array[position + 1])
        {
            isGreater = true;
        }
        Console.WriteLine();
        Console.WriteLine("The element at position '{0}' is bigger than its two neighbors - {1}", position, isGreater);
    }
}

